from django.shortcuts import render
from django.views import generic
from django.http import HttpResponse

from . import forms
from order.services import order


class CreatingOrder(generic.View):

    """ Создание заказа """

    def get(self, request):

        form = forms.CreatingOrderForm()
        context = {'form': form}
        return render(request, 'order/create.html', context)

    def post(self, request):

        bound_form = forms.CreatingOrderForm(request.POST)

        if bound_form.is_valid():
            
            created_order = bound_form.save()
            user_order = order.Order(request)
            user_order.place_order(created_order)
            return HttpResponse('Wake up, Neo...')
